{extend name="adminblue/base" /}
{block name="resources"/}
<script src="ADMIN_JS/art_dialog.source.js"></script>
<script src="ADMIN_JS/iframe_tools.source.js"></script>
<script src="ADMIN_JS/material_managedialog.js"></script>
<link rel="stylesheet" type="text/css" href="ADMIN_CSS/defau.css">
<style type="text/css">
input[type='radio']{float: left;margin-right: 5px;margin-top: 5px;}
label.line-label{display:inline-block;margin-right:10px;font-weight:normal;}
</style>
{/block}
{block name="main"}
<div class="set-style">
	<dl>
		<dt><span style="color:red;margin-right:10px;">*</span>导航名称</dt>
		<dd><input id="nav_title" type="text" class="input-common" name="title"/></dd>
	</dl>
	<dl>
		<dt>排序号</dt>
		<dd><input id="sort" type="number" value="0" class="input-common" min="0"/></dd>
	</dl>
	<dl>
		<dt><span style="color:red;margin-right:10px;">*</span>链接地址</dt>
		<dt style="width: 100px;text-align: left;">
			<label for="url_type1" style="margin-top: 5px;margin-left: 10px;"><input type="radio" value="0" name="url_type" id="url_type1" checked="checked"/>商城模块</label>
		</dt>
		<dt style="text-align: left;">
			<label for="url_type2" style="margin-top: 5px;"><input type="radio" value="1" name="url_type" id="url_type2" />自定义链接</label>
		</dt>
	</dl>
	<dl>
		<dt></dt>
		<dd>
			<select class="select-common" id="shopNavModel">
				<option value="">请选择</option>
				{notempty name="shopNavTemplate"}
				{foreach name="shopNavTemplate" item="vo"}
				<option value="{$vo.template_url}">{$vo.template_name}</option>
				{/foreach}
				{/notempty}
			</select>
			<span style="display: none;" id="nav_url">
				<input type="text" class="input-common" name="nav_url" style="width:210px;margin-bottom: 5px;"/>
				<span style="line-height: 28px;color: #999;">如：http://www.niushop.com.cn/</span>
			</span>
		</dd>
	</dl>
	<dl>
		<dt><span style="color:red;margin-left:15px;"></span>所在位置</dt>
		<dd>
			<div id="position_type">
				<label for="navigationtype1" class="line-label"><input type="radio" value="1" name="navigationtype" id="navigationtype1"/>头部</label>
				<label for="navigationtype2" class="line-label"><input type="radio" value="2" name="navigationtype" id="navigationtype2"/>中部</label>
				<label for="navigationtype3" class="line-label"><input type="radio" value="3" name="navigationtype" id="navigationtype3" checked="checked" />底部</label>
			</div>
		</dd>
	</dl>
	<dl>
		<dt>是否新窗口打开</dt>
		<dd>
			<div id="blank_type">
				<label for="is_blank1" class="line-label"><input type="radio" value="1" name="is_blank" id="is_blank1" />是</label>
				<label for="is_blank2" class="line-label"><input type="radio" value="0" name="is_blank" id="is_blank2" checked="checked" />否</label>
			</div>
		</dd>
	</dl>
	<dl>
		<dt></dt>
		<dd><button class="btn-common btn-big" onclick="save()">添加</button></dd>
	</dl>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
function save(){
	var nav_title=$("#nav_title").val();
	var sort=$("#sort").val();
	var type=$("input[name='navigationtype']:checked").val();
	if(nav_title == ''){
		showTip("导航名称不能为空","warning");
		$("#nav_title").focus();
		return false;	
	}
	if(sort=='')$("#sort").val(0);
	var url_type = $("input[name=url_type]:checked").val();
	if(url_type == 0){
	var nav_url=$("#shopNavModel").val();
	var template_name = $("#shopNavModel option:selected").text();
	}else if(url_type == 1){
		var nav_url=$("input[name=nav_url]").val();
		var template_name = '';
	}
	if(nav_url == ''){
		showTip("链接地址不能为空","warning");
		return false;
	}
	var is_blank = $("input[name=is_blank]:checked").val();
	$.ajax({
		type:"post",
		url:"{:__URL('ADMIN_MAIN/config/addshopnavigation')}",
		data:{
		'nav_title':nav_title,
		'sort':sort,
		'nav_url':nav_url,
		'type':type,
		'nav_type' : url_type,
		'is_blank' : is_blank,
		'template_name' : template_name
		},
		success:function(data){
			if (data["code"] > 0) {
				showMessage('success', data["message"]);
				location.href=__URL("ADMIN_MAIN/config/shopnavigationlist");
			}else{
				showMessage('error', data["message"]);
			}
		}
	});
}

$("#url_type1").click(function(){
	$("#shopNavModel").show();
	$("#nav_url").hide();
})
$("#url_type2").click(function(){
	$("#shopNavModel").hide();
	$("#nav_url").show();
})
</script>
{/block}